package com.tarena.sentinel.study.demo01;

import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
public class SentinelDemo01 {
    public static void main(String[] args) {
        SpringApplication.run(SentinelDemo01.class,args);
        // 在容器启动之后设置sentinel规则
        // 定义一个规则 数组 流控规则
        List<FlowRule> flowRules = new ArrayList<>();
        // 生成一个 规则对象
        FlowRule flowRule = new FlowRule();
        // 使用这个规则绑定一个资源
        flowRule.setResource("sayHi");
        // 设置限流方式 0=并发限流 1=qps限流
        flowRule.setGrade(1);
        // 限流阈值
        flowRule.setCount(1);
        // 添加到规则数组中
        flowRules.add(flowRule);
        // sentinel 加载这个数组
        FlowRuleManager.loadRules(flowRules);

    }
}
